<?php
require_once('../config/auth.php');
require_once('employe.cl.php');
$__CURRENT_PAGE__ = 'employe';
$__TITLE__ = "liste de modification des employés";
$employe = new Employe();
$serviceId = empty($_GET['service_id']) ? 0 : $_GET['service_id'];
$employes = $employe->getEmployesByServiceId($serviceId);
$departements = $employe->getService()->getDepartement()->getAllDepartements();

if(!empty($_GET['service_id'])) {
  $employe->getService()->loadServiceById($_GET['service_id']);
  $services = $employe->getService()->getServiceByDepartementId($employe->getService()->getDepartementId());
} else {
  $services = $employe->getService()->getAllServices();
}

require_once(dirname(__FILE__).'/../config/head.php');?>
<body>
<?php require_once(dirname(__FILE__).'/../config/menu.php'); ?>
<div class="container employeList">
  <a class="btn btn-success pull-right" href="form.php">Ajouter un employé</a><br>
    <select name="departement_id" id="departement_id">
          <option value="">--Selectionner un departement--</option>
          <?php foreach($departements as $depart): ?>
            <option <?php echo ($employe->getService()->getDepartementId() == $depart->id)  ? 'selected="selected"' : '' ?>
            value="<?php echo $depart->id?>"><?php echo $depart->name ?></option>   
          <?php endforeach ?>
  </select>
   <br><br>
  <select name="service_id" id="service_id">
          <option value="">--Selectionner un service--</option>
          <?php foreach($services as $serv): ?>
            <option <?php echo ($employe->getService()->getId() == $serv->id)  ? 'selected="selected"' : '' ?>
            value="<?php echo $serv->id?>"><?php echo $serv->name ?></option>   
          <?php endforeach ?>
  </select>
   <br>  <br>  <br>
	<table class="table table-striped" width="500" aling="center">
		<thead>
			<th>Matricule</th><th>Nom</th><th>Prénom</th><th>Post</th><th>Adresse</th><th>Téléphone du bureau</th><th>GSM</th><th>Ordre</th>
		</thead>
        <tbody>
        	<?php foreach($employes as $emp):?>
                <tr>
                	<td><?php echo $emp->matricule?></td><td><?php echo $emp->last_name?></td><td><?php echo $emp->first_name?></td>
                  <td><?php echo $emp->type?></td><td><?php echo $emp->adresse?></td><td><?php echo $emp->tele_bureau?></td>
                  <td><?php echo $emp->gsm?></td><td><?php echo $emp->order?></td>
                  <td> <?php echo "<a href='form.php?id=".$emp->id."'>modifier</a>" ?>
                </td>
                </tr>
            <?php endforeach ?>
        </tbody>
	</table>
</div>
</body>
